<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">


<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="indexClassId" name="indexClassId" class="form-control" type="hidden" maxlength="10" placeholder="" th:value="${indexClassId}">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品名称：</label>
                            <div class="col-sm-4">
                                <input id="productIds" name="productIds" class="form-control" type="hidden" placeholder="">
                                <input id="productId" name="productId" class="form-control" type="hidden" maxlength="10" placeholder="" readonly>
                                <textarea id="productName" name="productName" class="form-control" type="text" placeholder="" readonly></textarea>
<!--                                <input id="productName" name="productName" class="form-control" type="text" placeholder="" readonly>-->
                            </div>
                            <div class="col-sm-4">
                                <button type="button" class="btn btn-primary" onclick="selectProduct()">选择</button>
                            </div>
                        </div>
                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 control-label">所属首页商品分类：</label>-->
                            <!--<div class="col-sm-10">-->
                                <!--<select name="indexClassId" id="indexClassId"  >-->
                                    <!--<option value="">&#45;&#45;请选择所属商品分类&#45;&#45;</option>-->
                                    <!--<option th:each="indexClass,appStat:${indexClassCfgs}" th:value="${indexClass.indexClassId}" th:text="${indexClass.classTypeName}"></option>-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <div class="text-right form-group">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function () {
        validateRule();

    });

    function selectProduct() {

        layer.open({
            type: 2,
            title: '选择',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['1300px', '720px'],
            content: '/app/product/selectIndex'// iframe的url
        });
    }

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });


    function save() {
        var productIds = $('#productIds').val();
        $.ajax({
            cache: true,
            type: "POST",
            url: "/app/indexProduct/save",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            success: function (data) {
                layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                productName: {
                    required: true
                },
                indexClassId:{
                    required: true
                }
            },
            messages: {
                productName: {
                    required: icon + "必填"
                },
                indexClassId: {
                    required: icon + "必填"
                }
            }
        })
    }

</script>
</body>
</html>